/**
 * 
 */
package com.leyu.mall.site.user.controller;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.leyu.mall.service.user.UserService;

/**
 * @author change
 * 
 */
@Controller
@RequestMapping(value = "/user")
public class UserManagementController {
	@Autowired
	private UserService userService;
	@RequestMapping(value = "changePassword", method = RequestMethod.GET)
	public String changePassword() {
		return "user/changePassword.html";
	}

	@RequestMapping(value = "changePassword", method = RequestMethod.POST)
	public String changePassword(Form form) {
		if (StringUtils.isBlank(form.newPassword1)
				|| !form.newPassword1.equals(form.newPassword2)) {
			return "user/changePassword.html";
		}
		userService.changePassword(UserUtils.getLoginedUserName(), form.oldPassword, form.newPassword1);
		return "redirect:/login";
	}

	public static class Form {
		private String oldPassword;
		private String newPassword1;
		private String newPassword2;

		public String getOldPassword() {
			return oldPassword;
		}

		public void setOldPassword(String oldPassword) {
			this.oldPassword = oldPassword;
		}

		public String getNewPassword1() {
			return newPassword1;
		}

		public void setNewPassword1(String newPassword1) {
			this.newPassword1 = newPassword1;
		}

		public String getNewPassword2() {
			return newPassword2;
		}

		public void setNewPassword2(String newPassword2) {
			this.newPassword2 = newPassword2;
		}

	}
}
